﻿using System;
using System.Collections.Generic;
using System.Text;

using AKMII.DMRA.Common;

namespace AKMII.DMRA.DataAccess
{
    public class CommandHistoryAccessor
    {
        public DateTime GetLastExecuteTime(string command)
        {
            const string SpName = "sp_Get_LastExecuteTime";
            DateTime dateTime = DateTime.MinValue;

            try
            {
                object[] parameters = new object[] { command };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString, SpName, parameters);

                if (o != null)
                {
                    dateTime = Convert.ToDateTime(o);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occurs in get last execute time", ex);
            }

            return dateTime;
        }

        public void UpdateLastExecuteTime(string command, DateTime dateTime)
        {
            const string SpName = "sp_Update_LastExecuteTime";

            try
            {
                object[] parameters = new object[] { command, dateTime };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occurs in update last execute time", ex);
            }
        }
    }
}
